<template>
  	<div class="uploadWrap">
		<el-upload
		  class="avatar-uploader"
		  name="multipartFile"
		  :headers='headers'
		  action="/api/squirrel-ficm/file/upload"
		  :show-file-list="false"
		  :on-success="PicSuccess"
		  :beforeUpload="BeforePicUpload"
		  :on-error="PicError"
		  >
		  <el-button size="small" type="primary">点击上传</el-button>
		</el-upload>	
    </div>	
</template>

<script>
	import {headers} from "@/api/dust/personnel";	
	export default {
		data() {
			return { 
			   headers:headers(), // 自定义上传空间需要的权限	
			}
		},	
		methods:{
	        // 证件照上传成功后 执行的函数
	    	PicSuccess(res){
	    	 	this.$emit('success',res.data)
	    	},
	　　　      BeforePicUpload(file) {                 
	            var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)  
	            const extension = testmsg === 'jpg'
	            const extension2 = testmsg === 'png'
	            const isLt4M = file.size / 1024 / 1024 < 4
	            if(!extension && !extension2) {
	                this.$message({
	                    message: '上传文件只能是 jpg、png!',
	                    type: 'warning'
	                });
	            }
	            if(!isLt4M) {
	                this.$message({
	                    message: '上传文件大小不能超过 4MB!',
	                    type: 'warning'
	                });
	            }
	            return (extension || extension2) && isLt4M
	        },
	        PicError(){
                this.$message({
                    message: '文件上传失败',
                    type: 'error'
                });	        	
	        }
		}
	}
</script>

<style lang="scss">
	
</style>